package com.chinanet.utils.pon;

import java.io.*;
import java.net.Socket;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class H_SocketClient {

	private String ip;
	private int port;

	public H_SocketClient(String ip, int port) {
		this.ip = ip;
		this.port = port;
	}

	/**
	 * initfunction
	 * 
	 * @param hattr
	 * @param type
	 * @return
	 */
	public Map<String, Object> init(HW_Socket_AttrsIn hattr, OperationType type) {
		Map<String, Object> map = new HashMap<String, Object>();
		Socket socket = null;
		PrintWriter pw = null;
		InputStream in = null;
		// list的第一个代表成功与否，第二个代表自身log,第三个代表总log;
		List<Object> step = null;
		// 总日志
		String log = "";
		try {
			socket = new Socket(ip, port);
			pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
					socket.getOutputStream())));
			in = socket.getInputStream();

			step = Loginclient(pw, in, hattr.getUsername(),
					hattr.getPassword(), log);

			if (step == null) {
				map.put("Errormsg", "step error");
				return map;
			} else {
				boolean Flag = (Boolean) step.get(0);
				if (Flag) {
					log += step.get(2);
					if (type == OperationType.TYPE_Query_PON_port_luminous_power) {
						step = Query_PON_port_luminous_power(pw, in,
								hattr.getOLTID(), hattr.getPONID(), log);
						boolean flag = (Boolean) step.get(0);
						map.put("flag", flag);
						map.put("ownlog", step.get(1));
						map.put("log", step.get(2));
						return map;
					} else if (type == OperationType.TYPE_Query_ONU_number) {
						step = Query_ONU_number(pw, in, hattr.getOLTID(),
								hattr.getPONID(), log);
						boolean flag = (Boolean) step.get(0);
						map.put("flag", flag);
						map.put("ownlog", step.get(1));
						map.put("log", step.get(2));
						return map;

					} else if (type == OperationType.TYPE_Query_PON_OLT_under_the_number_of_alarms) {
						step = Query_PON_OLT_under_the_number_of_alarms(pw, in,
								hattr.getOLTID(), hattr.getPONID(),
								hattr.getBEGINTIME(), log);
						boolean flag = (Boolean) step.get(0);
						map.put("flag", flag);
						map.put("ownlog", step.get(1));
						map.put("log", step.get(2));
						return map;

					}else if(type == OperationType.TYPE_Query_LST_ONULANINFO){
						step=LST_ONULANINFO(pw,in,hattr.getOLTID(), hattr.getPONID(),
								hattr.getONUIDTYPE(),hattr.getONUID(),hattr.getONUPORT(), log);
						boolean flag = (Boolean) step.get(0);
						map.put("flag", flag);
						map.put("ownlog", step.get(1));
						map.put("log", step.get(2));
						return map;
					}else if (type == OperationType.TYPE_Query_ONU_STATE) {
						step = Query_ONU_STATE(pw, in,
								hattr.getOLTID(),hattr.getPONID(),hattr.getONUIDTYPE(),hattr.getONUID(), log);
						boolean flag = (Boolean) step.get(0);
						map.put("flag", flag);
						map.put("ownlog", step.get(1));
						map.put("log", step.get(2));
						return map;
					}else if (type == OperationType.TYPE_Query_PON_port_ONU_luminous_power) {
						step = Query_PON_port_onu_luminous_power(pw, in,
								hattr.getOLTID(), hattr.getPONID(), hattr.getONUIDTYPE(), hattr.getONUID(), log);
						boolean flag = (Boolean) step.get(0);
						map.put("flag", flag);
						map.put("ownlog", step.get(1));
						map.put("log", step.get(2));
						return map;
					}else if (type == OperationType.TYPE_Query_UNI_INFO) {
						step = Query_UNI_INFO(pw, in,
								hattr.getOLTID(), hattr.getPONID(), hattr.getONUIDTYPE(), hattr.getONUID(), log);
						boolean flag = (Boolean) step.get(0);
						map.put("flag", flag);
						map.put("ownlog", step.get(1));
						map.put("log", step.get(2));
						return map;
					}else if (type == OperationType.TYPE_RESET_ONU) {
						step = RESET_ONU(pw, in,
								hattr.getOLTID(), hattr.getPONID(), hattr.getONUIDTYPE(), hattr.getONUID(), log);
						boolean flag = (Boolean) step.get(0);
						map.put("flag", flag);
						map.put("ownlog", step.get(1));
						map.put("log", step.get(2));
						return map;
					}else if (type == OperationType.TYPE_Query_ONU_Version) {
						step = Query_ONU_Version(pw, in,
								hattr.getOLTID(), hattr.getPONID(), hattr.getONUIDTYPE(), hattr.getONUID(), log);
						boolean flag = (Boolean) step.get(0);
						map.put("flag", flag);
						map.put("ownlog", step.get(1));
						map.put("log", step.get(2));
						return map;
					}else if (type == OperationType.TYPE_Query_ONU_AgreementAndIp) {
						step = Query_ONU_AgreementAndIp(pw, in,
								hattr.getOLTID(), hattr.getPONID(), hattr.getONUIDTYPE(), hattr.getONUID(),hattr.getMGID(), log);
						boolean flag = (Boolean) step.get(0);
						map.put("flag", flag);
						map.put("ownlog", step.get(1));
						map.put("log", step.get(2));
						return map;
					}else if (type == OperationType.TYPE_Query_UserNumber) {
						step = Query_UserNumber(pw, in,
								hattr.getOLTID(), hattr.getPONID(), hattr.getONUIDTYPE(), hattr.getONUID(),hattr.getONUPORT(), log);
						boolean flag = (Boolean) step.get(0);
						map.put("flag", flag);
						map.put("ownlog", step.get(1));
						map.put("log", step.get(2));
						return map;
					}else if (type == OperationType.TYPE_Query_Cheack41_Bussinessbits) {
						step = Cheack41_Bussinessbits(pw, in,
								hattr.getOLTID(), hattr.getPONID(), hattr.getONUIDTYPE(), hattr.getONUID(), log);
						boolean flag = (Boolean) step.get(0);
						map.put("flag", flag);
						map.put("ownlog", step.get(1));
						map.put("log", step.get(2));
						return map;
					}else if (type == OperationType.TYPE_Simulation) {
						if(hattr.getFlag()==1){
							step = passiveSimulation(pw, in,
								hattr.getOLTID(), hattr.getPONID(), hattr.getONUIDTYPE(), hattr.getONUID(), hattr.getONUPORT(),log);
						}else{
							step=initiativeSimulation(pw, in,
									hattr.getOLTID(), hattr.getPONID(), hattr.getONUIDTYPE(), hattr.getONUID(), hattr.getONUPORT(),hattr.getTEL(),log);
						}
						boolean flag = (Boolean) step.get(0);
						map.put("flag", flag);
						map.put("ownlog", step.get(1));
						map.put("log", step.get(2));
						return map;
					}else if (type == OperationType.TYPE_HWFTTHB_RESETONU_MANAGER) {
						step = FTTNB_RESETONU_MANAGER(pw, in,
								hattr.getOLTID(),hattr.getONUPORT(), log);
						boolean flag = (Boolean) step.get(0);
						map.put("flag", flag);
						map.put("ownlog", step.get(1));
						map.put("log", step.get(2));
						return map;
					}else if (type == OperationType.TYPE_HWFTTHB_RESETONU_NOMANAGER) {
						step = FTTNB_RESETONU_NOMANAGER(pw, in, hattr.getONUID(), log);
						boolean flag = (Boolean) step.get(0);
						map.put("flag", flag);
						map.put("ownlog", step.get(1));
						map.put("log", step.get(2));
						return map;
					}else if(type==OperationType.TYPE_HW_Query_PON_Broadband_41){
						step = New_Broadband_41(pw, in,hattr.getOLTID(),hattr.getPONID(),hattr.getONUID(),hattr.getONUIDTYPE(),hattr.getSVLAN(),hattr.getCVLAN(),log);
						System.out.println("New_Broadband_41 log : "+step.get(2));
						boolean flag = (Boolean) step.get(0);
						map.put("flag", flag);
						map.put("ownlog", step.get(1));
						map.put("log", step.get(2));
						return map;
					}else if(type==OperationType.TYPE_HW_Query_PON_VOICE_46){
						step = VOICE_46(pw, in,hattr.getOLTID(),hattr.getPONID(),hattr.getONUID(),hattr.getONUIDTYPE(),hattr.getSVLAN(),hattr.getCVLAN(),log);
						boolean flag = (Boolean) step.get(0);
						map.put("flag", flag);
						map.put("ownlog", step.get(1));
						map.put("log", step.get(2));
						return map;
					}else if(type==OperationType.TYPE_HW_Query_PON_ITV43){
						step = ITV43(pw, in,hattr.getOLTID(),hattr.getPONID(),hattr.getONUID(),hattr.getONUIDTYPE(),hattr.getSVLAN(),hattr.getCVLAN(),hattr.getMAXGRP(),log);
						boolean flag = (Boolean) step.get(0);
						map.put("flag", flag);
						map.put("ownlog", step.get(1));
						map.put("log", step.get(2));
						return map;
					}

				} else {
					map.put("flag", Flag);
					map.put("ownlog", step.get(1));
					map.put("log", step.get(2));
					return map;
				}
			}

		} catch (Exception e) {
			StringWriter sw = new StringWriter();
			PrintWriter pwtwo = new PrintWriter(sw);
			e.printStackTrace(pwtwo);
			map.put("flag", false);
			map.put("log", "time out!");
			return map;

		} finally {
			try {
				pw.close();
			} catch (Exception e2) {
				map.put("flag", false);
				map.put("log", "time out!");
				return map;
			}
			try {
				in.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
			try {
				socket.close();
			} catch (IOException e) {
				e.printStackTrace();
			}

		}
		return map;

	}

	/**
	 * Login
	 * 
	 * @param pw
	 * @param in
	 * @param username
	 * @param password
	 * @param log
	 * @return
	 */
	public List<Object> Loginclient(PrintWriter pw, InputStream in,
			String username, String password, String log) {
		String cmd = "LOGIN:::CTAG::UN=" + username + ",PWD=" + password + ";";
		// initLogin
		pw.write(cmd);
		pw.flush();
		return initLogOut(in, log);
	}

	/**
	 * Query_PON_port_luminous_power
	 * 
	 * @param pw
	 * @param in
	 * @param OLTID
	 * @param PONID
	 * @param log
	 * @return
	 */
	public List<Object> Query_PON_port_luminous_power(PrintWriter pw,
			InputStream in, String OLTID, String PONID, String log) {
		String cmd = "LST-OMDDM::OLTID=" + OLTID + ",PONID=" + PONID
				+ ":CTAG::;";
		// initQuery
		pw.write(cmd);
		pw.flush();
		return initLogOut(in, log);
	}
	

	/**
	 * Query_PON_port_onu_luminous_power
	 * @param pw
	 * @param in
	 * @param OLTID
	 * @param PONID
	 * @param ONUIDTYPE
	 * @param ONUID
	 * @param log
	 * @return
	 */
	public List<Object> Query_PON_port_onu_luminous_power(PrintWriter pw,
			InputStream in, String OLTID, String PONID, String ONUIDTYPE, String ONUID,String log) {
		String cmd = "LST-OMDDM::OLTID=" + OLTID + ",PONID=" + PONID+",ONUIDTYPE="+ONUIDTYPE+",ONUID="+ONUID
				+ ":CTAG::;";
		// initQuery
		pw.write(cmd);
		pw.flush();
		return initLogOut(in, log);
	}
	
	/**
	 * Query_UNI_INFO
	 * @param pw
	 * @param in
	 * @param OLTID
	 * @param PONID
	 * @param ONUIDTYPE
	 * @param ONUID
	 * @param log
	 * @return
	 */
	public List<Object> Query_UNI_INFO(PrintWriter pw,
			InputStream in, String OLTID, String PONID, String ONUIDTYPE, String ONUID,String log) {
		String cmd = "LST-LANPORT::OLTID=" + OLTID + ",PONID=" + PONID+",ONUIDTYPE="+ONUIDTYPE+",ONUID="+ONUID
				+ ":CTAG::;";
		// initQuery
		pw.write(cmd);
		pw.flush();
		return initLogOut(in, log);
	}
	
	/**
	 * RESET_ONU
	 * @param pw
	 * @param in
	 * @param OLTID
	 * @param PONID
	 * @param ONUIDTYPE
	 * @param ONUID
	 * @param log
	 * @return
	 */
	public List<Object> RESET_ONU(PrintWriter pw,
			InputStream in, String OLTID, String PONID, String ONUIDTYPE, String ONUID,String log) {
		String cmd = "RESET-ONU::OLTID=" + OLTID + ",PONID=" + PONID+",ONUIDTYPE="+ONUIDTYPE+",ONUID="+ONUID
				+ ":CTAG::;";
		// initQuery
		pw.write(cmd);
		pw.flush();
		return initLogOut(in, log);
	}
	
	/**
	 * Query_ONU_Version
	 * @param pw
	 * @param in
	 * @param OLTID
	 * @param PONID
	 * @param ONUIDTYPE
	 * @param ONUID
	 * @param log
	 * @return
	 */
	public List<Object> Query_ONU_Version(PrintWriter pw,
			InputStream in, String OLTID, String PONID, String ONUIDTYPE, String ONUID,String log) {
		String cmd = "LST-ONU::OLTID=" + OLTID + ",PONID=" + PONID+",ONUIDTYPE="+ONUIDTYPE+",ONUID="+ONUID
				+ ":CTAG::;";
		// initQuery
		pw.write(cmd);
		pw.flush();
		return initLogOut(in, log);
	}
	
	/**
	 * Query_ONU_AgreementAndIp
	 * @param pw
	 * @param in
	 * @param OLTID
	 * @param PONID
	 * @param ONUIDTYPE
	 * @param ONUID
	 * @param MGID
	 * @param log
	 * @return
	 */
	public List<Object> Query_ONU_AgreementAndIp(PrintWriter pw,
			InputStream in, String OLTID, String PONID, String ONUIDTYPE, String ONUID,String MGID,String log) {
		String cmd = "LST-MGCFG::OLTID=" + OLTID + ",PONID=" + PONID+",ONUIDTYPE="+ONUIDTYPE+",ONUID="+ONUID+",MGID="+MGID
				+ ":CTAG::;";
		// initQuery
		pw.write(cmd);
		pw.flush();
		return initLogOut(in, log);
	}
	
	/**
	 * Query_UserNumber
	 * @param pw
	 * @param in
	 * @param OLTID
	 * @param PONID
	 * @param ONUIDTYPE
	 * @param ONUID
	 * @param ONUPORT
	 * @param log
	 * @return
	 */
	public List<Object> Query_UserNumber(PrintWriter pw,
			InputStream in, String OLTID, String PONID, String ONUIDTYPE, String ONUID,String ONUPORT,String log) {
		String cmd = "LST-POTSINFO::OLTID=" + OLTID + ",PONID=" + PONID+",ONUIDTYPE="+ONUIDTYPE+",ONUID="+ONUID+",ONUPORT="+ONUPORT
				+ ":123::;";
		// initQuery
		pw.write(cmd);
		pw.flush();
		return initLogOut(in, log);
	}
	
	/**
	 * passiveSimulation
	 * @param pw
	 * @param in
	 * @param OLTID
	 * @param PONID
	 * @param ONUIDTYPE
	 * @param ONUID
	 * @param ONUPORT
	 * @param log
	 * @return
	 */
	public List<Object> passiveSimulation(PrintWriter pw,
			InputStream in, String OLTID, String PONID, String ONUIDTYPE, String ONUID,String ONUPORT,String log) {
		String cmd = "TEST-CALLEESIMULATION::OLTID=" + OLTID + ",PONID=" + PONID+",ONUIDTYPE="+ONUIDTYPE+",ONUID="+ONUID+",ONUPORT="+ONUPORT
				+ ":123::ACTION=Start;";
		pw.write(cmd);
		pw.flush();
		List<Object> back=initLogOut(in, log);
		boolean flag=(boolean) back.get(0);
		String logone=(String) back.get(2);
		if(flag){
			String cmdtwo = "TEST-CALLEESIMULATION::OLTID=" + OLTID + ",PONID=" + PONID+",ONUIDTYPE="+ONUIDTYPE+",ONUID="+ONUID+",ONUPORT="+ONUPORT
					+ ":123::ACTION=Query;";
			pw.write(cmdtwo);
			pw.flush();
			List<Object> backone=initLogOut(in, logone);
			flag=(boolean) backone.get(0);
			logone=(String) backone.get(2);
			if(flag){
				String cmdthree = "TEST-CALLEESIMULATION::OLTID=" + OLTID + ",PONID=" + PONID+",ONUIDTYPE="+ONUIDTYPE+",ONUID="+ONUID+",ONUPORT="+ONUPORT
						+ ":123::ACTION=Stop;";
				pw.write(cmdthree);
				pw.flush();
				return initLogOut(in, logone);
			}else{
				return backone;
			}
		}else{
			return back;
		}
		
	}
	
	/**
	 * initiativeSimulation
	 * @param pw
	 * @param in
	 * @param OLTID
	 * @param PONID
	 * @param ONUIDTYPE
	 * @param ONUID
	 * @param ONUPORT
	 * @param TEL
	 * @param log
	 * @return
	 */
	public List<Object> initiativeSimulation(PrintWriter pw,
			InputStream in, String OLTID, String PONID, String ONUIDTYPE, String ONUID,String ONUPORT,String TEL,String log) {
		
		String cmd = "TEST-CALLERSIMULATION::OLTID=" + OLTID + ",PONID=" + PONID+",ONUIDTYPE="+ONUIDTYPE+",ONUID="+ONUID+",ONUPORT="+ONUPORT
				+ ":123::ACTION=Start,TEL="+TEL+";";
		pw.write(cmd);
		pw.flush();
		List<Object> back=initLogOut(in, log);
		boolean flag=(boolean) back.get(0);
		String logone=(String) back.get(2);
		if(flag){
			String cmdtwo = "TEST-CALLERSIMULATION::OLTID=" + OLTID + ",PONID=" + PONID+",ONUIDTYPE="+ONUIDTYPE+",ONUID="+ONUID+",ONUPORT="+ONUPORT
					+ ":123::ACTION=Query,TEL="+TEL+";";
			pw.write(cmdtwo);
			pw.flush();
			List<Object> backone=initLogOut(in, logone);
			flag=(boolean) backone.get(0);
			logone=(String) backone.get(2);
			if(flag){
				String cmdthree = "TEST-CALLERSIMULATION::OLTID=" + OLTID + ",PONID=" + PONID+",ONUIDTYPE="+ONUIDTYPE+",ONUID="+ONUID+",ONUPORT="+ONUPORT
						+ ":123::ACTION=Stop,TEL="+TEL+";";
				pw.write(cmdthree);
				pw.flush();
				return initLogOut(in, logone);
			}else{
				return backone;
			}
		}else{
			return back;
		}
		
	}
	
	
	/**
	 * Cheack41_Bussinessbits
	 * @param pw
	 * @param in
	 * @param OLTID
	 * @param PONID
	 * @param ONUIDTYPE
	 * @param ONUID
	 * @param log
	 * @return
	 */
	public List<Object> Cheack41_Bussinessbits(PrintWriter pw,
			InputStream in, String OLTID, String PONID, String ONUIDTYPE, String ONUID,String log) {
		String cmd = "LST-PONVLAN::OLTID=" + OLTID + ",PONID=" + PONID+",ONUIDTYPE="+ONUIDTYPE+",ONUID="+ONUID
				+ ":CTAG::;";
		// initQuery
		pw.write(cmd);
		pw.flush();
		return initLogOut(in, log);
	}
	
	
	
	

	/**
	 * Query the number of ONU under PON OLT port
	 * 
	 * @param pw
	 * @param in
	 * @param OLTID
	 * @param PONID
	 * @param log
	 * @return
	 */
	public List<Object> Query_ONU_number(PrintWriter pw, InputStream in,
			String OLTID, String PONID, String log) {
		String cmd = "LST-ONU::OLTID=" + OLTID + ",PONID=" + PONID + ":CTAG::;";
		// initQuery
		pw.write(cmd);
		pw.flush();
		return initLogOut(in, log);
	}

	
	/**
	 * Query PON OLT under the number of alarms
	 * @param pw
	 * @param in
	 * @param OLTID
	 * @param PONID
	 * @param BEGINTIME
	 * @param
	 * @param log
	 * @return
	 */
	//LST-ALARM::OLTID=10.133.35.2,PONID=NA-0-4-2:CTAG::BEGINTIME=2016-10-21 13-05-00,FAULTFLAG=Fault-Only;")
	public List<Object> Query_PON_OLT_under_the_number_of_alarms(
			PrintWriter pw, InputStream in, String OLTID, String PONID,
			String BEGINTIME, String log) {
		String cmd = "LST-ALARM::OLTID=" + OLTID + ",PONID=" + PONID
				+ ":CTAG::BEGINTIME=" + BEGINTIME +",FAULTFLAG=Fault-Only;";
		// initQuery
		pw.write(cmd);
		pw.flush();
		return initLogOut(in, log);
	}

	public List<Object> Query_ONU_STATE(PrintWriter pw,
										InputStream in,String OLTID,String PONID,String ONUIDTYPE,String ONUID, String log) {
		String cmd = "LST-ONUSTATE::OLTID="+OLTID+",PONID="+PONID+",ONUIDTYPE="+ONUIDTYPE+",ONUID="+ONUID
				+ ":CTAG::;";
		// initQuery
		pw.write(cmd);
		pw.flush();
		return initLogOut(in, log);
	}

	  
	/**
	 * LST_ONULANINFO
	 * @param pw
	 * @param in
	 * @param OLTID
	 * @param PONID
	 * @param ONUIDTYPE
	 * @param ONUID
	 * @param ONUPORT
	 * @param log
	 * @return
	 */
	public List<Object> LST_ONULANINFO(PrintWriter pw, InputStream in, String OLTID, String PONID,
			String ONUIDTYPE, String ONUID, String ONUPORT, String log){
		String cmd ="LST-ONULANINFO::OLTID="+OLTID+",PONID="+PONID+",ONUIDTYPE="+ONUIDTYPE+",ONUID="+ONUID+",ONUPORT="+ONUPORT+":CTAG::;";
		pw.write(cmd);
		pw.flush();
		return initLogOut(in, log);
	}

	/**
	 * 执行输出
	 * 
	 * @param in
	 * @param log
	 * @return
	 */
	private List<Object> initLogOut(InputStream in, String log) {
		// list的第一个代表成功与否，第二个代表自身log,第三个代表总log;
		List<Object> loginLogs = new ArrayList<Object>();
		byte[] b = new byte[1024];
		StringBuffer sb = new StringBuffer();
		int len = 0;

		boolean flag = false;
		boolean flagtrue = false;
		boolean flagfalse = false;
		try {
			while ((len = in.read(b)) != -1) {
				String str = new String(b, 0, len, "gbk");
				sb.append(str);
				if ((str.indexOf("EN=0")) != -1) {
					flagtrue = true;
				}
				if ((str.indexOf("ErrorCode")) != -1) {
					flagfalse = true;
				}
				if (flagtrue && (str.indexOf(";")) != -1) {

					flag = true;
					break;
				}
				if (flagfalse && (str.indexOf(";")) != -1) {

					break;
				}

			}

			log += sb.toString();
			loginLogs.add(flag);
			loginLogs.add(sb.toString());
			loginLogs.add(log);
			return loginLogs;
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return loginLogs;

	}

	/**
	 * @description  华为ONU去激活再激活(不具有独立管理IP)
	 * @Author jwing
	 * @Date 9:22 2018/1/16
	 */
	public List<Object> FTTNB_RESETONU_NOMANAGER(PrintWriter pw,
												 InputStream in,String ONUID, String log) {
		// TODO: 指令未确认
		String cmd = "DACTLANPORT::OLTID=10.78.217.109,PONID=NA-0-6-1,ONUIDTYPE=LOID,ONUID="+ONUID
				+ ",ONUPORT=NA-NA-NA-1:CTAG::;";
		pw.write(cmd);
		pw.flush();
		log = initLogOut(in, log).get(2).toString();

		cmd = "ACTLANPORT::OLTID=10.78.217.109,PONID=NA-0-6-1,ONUIDTYPE=LOID,ONUID="+ONUID
				+ ",ONUPORT=NA-NA-NA-1:CTAG::;";
		pw.write(cmd);
		pw.flush();
		return initLogOut(in, log);
	}
	/**
	 * @description  华为ONU去激活再激活(具有独立管理IP)
	 * @Author jwing
	 * @Date 9:22 2018/1/16
	 */
	public List<Object> FTTNB_RESETONU_MANAGER(PrintWriter pw,
											   InputStream in,String ONUIP,String ONUPORT, String log) {
		// 去激活
		String cmd = "DACT-LANPORT::ONUIP=" + ONUIP + ",ONUPORT=" + ONUPORT + ":CTAG::;";
		pw.write(cmd);
		pw.flush();
		List<Object> result = initLogOut(in, log);
		if ((Boolean) result.get(0) == false) { // 去激活失败
			return result;
		}
		log = result.get(2).toString();
		// 激活
		cmd = "ACT-LANPORT::ONUIP=" + ONUIP + ",ONUPORT=" + ONUPORT + ":CTAG::;";
		pw.write(cmd);
		pw.flush();
		return initLogOut(in, log);
	}



	/**
	 * @author zsf
	 * @date 2018/1/30 13:43
	 * @return java.util.List<java.lang.Object>
	 * @desc 华为PON网管新建宽带41
	 */
	public List<Object> New_Broadband_41(PrintWriter pw,InputStream in,String OLTID,String PONID, String ONUID,String ONUIDTYPE,String SVLAN,String CVLAN,String log) {

		//TODO 指令可能会改
		String cmd = "ADD-PONVLAN::OLTID="+OLTID+",PONID="+PONID+",ONUIDTYPE="+ONUIDTYPE
						+",ONUID="+ONUID+":CTAG::SVLAN="+SVLAN+",CVLAN="+CVLAN+",UV=41,SCOS=1,CCOS=1;";
		pw.write(cmd);
		pw.flush();
		return initLogOut(in, log);
	}

	/**
	 * @author zsf
	 * @date 2018/1/30 13:43
	 * @return java.util.List<java.lang.Object>
	 * @desc 华为PON网管语音46
	 */
	public List<Object>VOICE_46 (PrintWriter pw,InputStream in,String OLTID,String PONID, String ONUID,String ONUIDTYPE,String SVLAN,String CVLAN,String log) {

		//TODO 指令可能会改
		String cmd = "ADD-PONVLAN::OLTID="+OLTID+",PONID="+PONID+",ONUIDTYPE="+ONUIDTYPE
						+",ONUID="+ONUID+":CTAG::SVLAN="+SVLAN+",CVLAN="+CVLAN+",UV=46,SCOS=7,CCOS=7;";
		pw.write(cmd);
		pw.flush();
		return initLogOut(in, log);
	}

	/**
	 * @author zsf
	 * @date 2018/1/30 13:43
	 * @return java.util.List<java.lang.Object>
	 * @desc 华为PON网管ITV43
	 */
	public List<Object> ITV43(PrintWriter pw,InputStream in,String OLTID,String PONID, String ONUID,String ONUIDTYPE,String SVLAN,String CVLAN,String MAXGRP,String log) throws InterruptedException {

		//TODO 指令可能会改
		//开通IPTV业务流
		String cmd = "ADD-PONVLAN::OLTID="+OLTID+",PONID="+PONID+",ONUIDTYPE="+ONUIDTYPE
						+",ONUID="+ONUID+":CTAG::SVLAN="+SVLAN+",CVLAN="+CVLAN+",UV=43,SCOS=4,CCOS=4;";
		pw.write(cmd);
		pw.flush();
		List<Object> result = initLogOut(in, log);
		log = result.get(2).toString();
		if((Boolean) result.get(0)) {
			//用户加入组播vlan
			cmd = "ADD-LANIPTVPORT::OLTID=" + OLTID + ",PONID=" + PONID + ",ONUIDTYPE=" + ONUIDTYPE
					+ ",ONUID=" + ONUID + ":CTAG::UV=43,MVLAN=4000;";
			pw.write(cmd);
			pw.flush();
			log = result.get(2).toString();
			Thread.sleep(2000);
			if ((Boolean) result.get(0)) {
				// 修改组播vlan属性
				cmd = "CFG-LANIPTVPORT::OLTID=" + OLTID + ",PONID=" + PONID + ",ONUIDTYPE=" + ONUIDTYPE
						+ ",ONUID=" + ONUID + ":CTAG::MAXGRP=" + MAXGRP + ";";
				System.out.println("\n\ncmd:\n\n"+cmd);
				pw.write(cmd);
				pw.flush();
				result = initLogOut(in, log);
			}
		}
		return result;
	}
}
